    package cn.tedu.charging.order.config;

    import cn.tedu.charging.common.constant.AmqpComponentConst;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.amqp.core.*;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;

    @Configuration
    @Slf4j
    public class DeclareConfiguration {
        //为上述的命名 声明一套延迟队列的结构
        //1.业务交换机
        @Bean
        public Exchange transEx(){
            //channel.exchangeDeclare("",DIRECT)
            //1.直接new
            return ExchangeBuilder.fanoutExchange(AmqpComponentConst.DELAY_BILL_EX).build();
        }
        //2.延迟交换机
        @Bean
        public Exchange delayEx(){
            return ExchangeBuilder.directExchange(AmqpComponentConst.DELAY_BILL_DL_EX).build();
        }
        //3.延迟队列
        @Bean
        public Queue delayQ(){
            return QueueBuilder.nonDurable(AmqpComponentConst.DELAY_BILL_DL_QUEUE).build();
        }
        //4.业务队列
        @Bean
        public Queue transQ(){
            return QueueBuilder.nonDurable(AmqpComponentConst.DELAY_BILL_QUEUE).deadLetterRoutingKey(AmqpComponentConst.DELAY_BILL_DL_RK).deadLetterExchange(AmqpComponentConst.DELAY_BILL_DL_EX).build();
        }
        //两组绑定关系
        @Bean
        public Binding bindTrans(){
            return BindingBuilder.bind(transQ()).to(transEx()).with("").noargs();
        }
        @Bean
        public Binding bindDelay(){
            return BindingBuilder.bind(delayQ()).to(delayEx()).with(AmqpComponentConst.DELAY_BILL_DL_RK).noargs();
        }
    }
